package gui;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import source.*;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author padsilva
 */
public class UtilizadorMenuEditarPerfil extends javax.swing.JFrame {

    DatabaseHandler connect;
    int id;
    String username;
    File file;

    /**
     * Creates new form UtilizadorMenuEditarPerfil
     */
    public UtilizadorMenuEditarPerfil(DatabaseHandler conn, String usernameReceived, int idReceived) {
        id = idReceived;
        username = usernameReceived;
        connect = conn;
        initComponents();
        this.sucesso.setVisible(false);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        this.setLocation((screenSize.width - this.getWidth()) / 2, (screenSize.height - this.getHeight()) / 2);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jComboBox1 = new javax.swing.JComboBox();
        jScrollPane2 = new javax.swing.JScrollPane();
        jEditorPane1 = new javax.swing.JEditorPane();
        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jCheckBoxPassword = new javax.swing.JCheckBox();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        emailText = new javax.swing.JTextField();
        jCheckBoxEmail = new javax.swing.JCheckBox();
        jLabel3 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        localidadeText = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jCheckBoxLocalidade = new javax.swing.JCheckBox();
        jLabel5 = new javax.swing.JLabel();
        passwordText = new javax.swing.JPasswordField();
        repeatPassword = new javax.swing.JPasswordField();
        jScrollPane1 = new javax.swing.JScrollPane();
        interessesText = new javax.swing.JTextArea();
        jCheckBoxInteresses = new javax.swing.JCheckBox();
        jPanel5 = new javax.swing.JPanel();
        jCheckBoxTipoPerfil = new javax.swing.JCheckBox();
        jLabel6 = new javax.swing.JLabel();
        perfilPublico = new javax.swing.JRadioButton();
        perfilPrivado = new javax.swing.JRadioButton();
        jPanel6 = new javax.swing.JPanel();
        checkAlterarFoto = new javax.swing.JCheckBox();
        buttonAnexarFoto = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jPanel9 = new javax.swing.JPanel();
        actualizar = new javax.swing.JButton();
        buttonVoltar = new javax.swing.JButton();
        sucesso = new javax.swing.JLabel();
        barraMenus = new javax.swing.JMenuBar();
        menuPrincipal = new javax.swing.JMenu();
        botaoUtilizadorMenuPrincipal = new javax.swing.JMenuItem();
        menuMensagensPrivadas = new javax.swing.JMenu();
        botaoUtilizadorMenuMensagensPrivadas = new javax.swing.JMenuItem();
        botaoUtilizadorMensagensEnviadas = new javax.swing.JMenuItem();
        botaoUtilizadorMensagensRecebidas = new javax.swing.JMenuItem();
        botaoMenuMensagensNovas = new javax.swing.JMenuItem();
        menuPerfil = new javax.swing.JMenu();
        botaoParaUtilizadorMenuEditarPerfil = new javax.swing.JMenuItem();
        botaoRemoveSai = new javax.swing.JMenuItem();
        menuProcurar = new javax.swing.JMenu();
        botaoMenuProcurarUtilizador = new javax.swing.JMenuItem();
        menuSalas = new javax.swing.JMenu();
        botaoMinhasSalas = new javax.swing.JMenuItem();
        botaoPesquisarSalas = new javax.swing.JMenuItem();

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jScrollPane2.setViewportView(jEditorPane1);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jCheckBoxPassword.setText("Alterar Password");
        jCheckBoxPassword.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxPasswordActionPerformed(evt);
            }
        });

        jLabel2.setText("Repita a nova password:");

        jLabel1.setText("Insira nova password:");

        jCheckBoxEmail.setText("Alterar E-mail");

        jLabel3.setText("Insira um novo e-mail:");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jLabel3)
                .addGap(26, 26, 26)
                .addComponent(emailText, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jCheckBoxEmail)
                .addContainerGap(17, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(emailText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCheckBoxEmail))
                .addGap(0, 9, Short.MAX_VALUE))
        );

        jLabel4.setText("Cidade / Localidade:");

        jCheckBoxLocalidade.setText("Alterar Localidade");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jLabel4)
                .addGap(34, 34, 34)
                .addComponent(localidadeText, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jCheckBoxLocalidade, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(localidadeText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCheckBoxLocalidade))
                .addGap(0, 15, Short.MAX_VALUE))
        );

        jLabel5.setText("Insira os interesses:");

        passwordText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                passwordTextActionPerformed(evt);
            }
        });

        interessesText.setColumns(20);
        interessesText.setRows(5);
        jScrollPane1.setViewportView(interessesText);

        jCheckBoxInteresses.setText("Alterar Interesses");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(20, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addGap(12, 12, 12)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(repeatPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)
                            .addComponent(passwordText))
                        .addGap(18, 18, 18)
                        .addComponent(jCheckBoxPassword))
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel5)
                            .addGap(34, 34, 34)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(18, 18, 18)
                            .addComponent(jCheckBoxInteresses))
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(23, 23, 23))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(passwordText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(repeatPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(17, 17, 17)
                        .addComponent(jCheckBoxPassword)))
                .addGap(18, 18, 18)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCheckBoxInteresses))
                .addGap(76, 76, 76))
        );

        jCheckBoxTipoPerfil.setText("Alterar tipo Perfil");
        jCheckBoxTipoPerfil.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxTipoPerfilActionPerformed(evt);
            }
        });

        jLabel6.setText("Tipo de Perfil:");

        buttonGroup1.add(perfilPublico);
        perfilPublico.setText("Publico");

        buttonGroup1.add(perfilPrivado);
        perfilPrivado.setText("Privado");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(perfilPublico)
                .addGap(10, 10, 10)
                .addComponent(perfilPrivado)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jCheckBoxTipoPerfil)
                .addGap(46, 46, 46))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jCheckBoxTipoPerfil)
                    .addComponent(perfilPublico)
                    .addComponent(perfilPrivado))
                .addContainerGap(9, Short.MAX_VALUE))
        );

        checkAlterarFoto.setText("Alterar Foto");

        buttonAnexarFoto.setText("Procurar...");
        buttonAnexarFoto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonAnexarFotoActionPerformed(evt);
            }
        });

        jLabel7.setText("Alterar Foto:");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(jLabel7)
                .addGap(49, 49, 49)
                .addComponent(buttonAnexarFoto)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(checkAlterarFoto)
                .addGap(78, 78, 78))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
            .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(buttonAnexarFoto)
                .addComponent(jLabel7)
                .addComponent(checkAlterarFoto))
        );

        actualizar.setText("Atualizar");
        actualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                actualizarActionPerformed(evt);
            }
        });

        buttonVoltar.setText("Voltar");
        buttonVoltar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonVoltarActionPerformed(evt);
            }
        });

        sucesso.setText("Campos Atualizados!");

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel9Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(sucesso)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(buttonVoltar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(actualizar, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(21, 21, 21))
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(actualizar, javax.swing.GroupLayout.DEFAULT_SIZE, 43, Short.MAX_VALUE)
                        .addComponent(buttonVoltar))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel9Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(sucesso)))
                .addContainerGap())
        );

        menuPrincipal.setText("Menu Principal");

        botaoUtilizadorMenuPrincipal.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_H, java.awt.event.InputEvent.CTRL_MASK));
        botaoUtilizadorMenuPrincipal.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/home-icon.png"))); // NOI18N
        botaoUtilizadorMenuPrincipal.setText("Home");
        botaoUtilizadorMenuPrincipal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoUtilizadorMenuPrincipalActionPerformed(evt);
            }
        });
        menuPrincipal.add(botaoUtilizadorMenuPrincipal);

        barraMenus.add(menuPrincipal);

        menuMensagensPrivadas.setText("Mensagens Privadas");

        botaoUtilizadorMenuMensagensPrivadas.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        botaoUtilizadorMenuMensagensPrivadas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon mensagem nova.png"))); // NOI18N
        botaoUtilizadorMenuMensagensPrivadas.setText("Criar");
        botaoUtilizadorMenuMensagensPrivadas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoUtilizadorMenuMensagensPrivadasActionPerformed(evt);
            }
        });
        menuMensagensPrivadas.add(botaoUtilizadorMenuMensagensPrivadas);

        botaoUtilizadorMensagensEnviadas.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        botaoUtilizadorMensagensEnviadas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon mensagem enviadas.png"))); // NOI18N
        botaoUtilizadorMensagensEnviadas.setText("Enviadas");
        botaoUtilizadorMensagensEnviadas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoUtilizadorMensagensEnviadasActionPerformed(evt);
            }
        });
        menuMensagensPrivadas.add(botaoUtilizadorMensagensEnviadas);

        botaoUtilizadorMensagensRecebidas.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        botaoUtilizadorMensagensRecebidas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon mensagens recebidas.png"))); // NOI18N
        botaoUtilizadorMensagensRecebidas.setText("Recebidas");
        botaoUtilizadorMensagensRecebidas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoUtilizadorMensagensRecebidasActionPerformed(evt);
            }
        });
        menuMensagensPrivadas.add(botaoUtilizadorMensagensRecebidas);

        botaoMenuMensagensNovas.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        botaoMenuMensagensNovas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/1355506850_label_new blue.png"))); // NOI18N
        botaoMenuMensagensNovas.setText("Novas Mensagens");
        botaoMenuMensagensNovas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoMenuMensagensNovasActionPerformed(evt);
            }
        });
        menuMensagensPrivadas.add(botaoMenuMensagensNovas);

        barraMenus.add(menuMensagensPrivadas);

        menuPerfil.setText("Perfil");

        botaoParaUtilizadorMenuEditarPerfil.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.CTRL_MASK));
        botaoParaUtilizadorMenuEditarPerfil.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon editar perfil.png"))); // NOI18N
        botaoParaUtilizadorMenuEditarPerfil.setText("Editar");
        botaoParaUtilizadorMenuEditarPerfil.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoParaUtilizadorMenuEditarPerfilActionPerformed(evt);
            }
        });
        menuPerfil.add(botaoParaUtilizadorMenuEditarPerfil);

        botaoRemoveSai.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK));
        botaoRemoveSai.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon remover utilizador.png"))); // NOI18N
        botaoRemoveSai.setText("Remover");
        botaoRemoveSai.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoRemoveSaiActionPerformed(evt);
            }
        });
        menuPerfil.add(botaoRemoveSai);

        barraMenus.add(menuPerfil);

        menuProcurar.setText("Procurar Utilizadores");

        botaoMenuProcurarUtilizador.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_MASK));
        botaoMenuProcurarUtilizador.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon procurar utilizador.png"))); // NOI18N
        botaoMenuProcurarUtilizador.setText("Procurar");
        botaoMenuProcurarUtilizador.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoMenuProcurarUtilizadorActionPerformed(evt);
            }
        });
        menuProcurar.add(botaoMenuProcurarUtilizador);

        barraMenus.add(menuProcurar);

        menuSalas.setText("Salas");

        botaoMinhasSalas.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M, java.awt.event.InputEvent.CTRL_MASK));
        botaoMinhasSalas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon minhas salas.png"))); // NOI18N
        botaoMinhasSalas.setText("Minhas Salas");
        botaoMinhasSalas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoMinhasSalasActionPerformed(evt);
            }
        });
        menuSalas.add(botaoMinhasSalas);

        botaoPesquisarSalas.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        botaoPesquisarSalas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon procurar sala.png"))); // NOI18N
        botaoPesquisarSalas.setText("Pesquisar");
        botaoPesquisarSalas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoPesquisarSalasActionPerformed(evt);
            }
        });
        menuSalas.add(botaoPesquisarSalas);

        barraMenus.add(menuSalas);

        setJMenuBar(barraMenus);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 312, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(9, 9, 9)
                .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jCheckBoxTipoPerfilActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxTipoPerfilActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jCheckBoxTipoPerfilActionPerformed

    private void actualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_actualizarActionPerformed
        // TODO add your handling code here:
        boolean boolPublico = false;
        boolean boolAdministrador = false;
        String newfilename = "";

        String user = connect.getUser(username);
        StringTokenizer st = new StringTokenizer(user, "#");
        int idR = Integer.parseInt(st.nextToken());
        String nome = st.nextToken();
        String utilizador = st.nextToken();
        String password = st.nextToken();
        String datanascimento = st.nextToken();
        String sexo = st.nextToken();
        String email = st.nextToken();
        String pais = st.nextToken();
        String cidade = st.nextToken();
        String interesses = st.nextToken();
        String fotos = st.nextToken();
        int publico = Integer.parseInt(st.nextToken());
        if (publico == 1) {
            boolPublico = true;
        }

        int administrador = Integer.parseInt(st.nextToken());
        if (administrador == 1) {
            boolAdministrador = true;
        }


        if (jCheckBoxEmail.isSelected()) {
            email = emailText.getText();
        } else if (jCheckBoxLocalidade.isSelected()) {
            cidade = localidadeText.getText();
        } else if (jCheckBoxInteresses.isSelected()) {

            interesses = interessesText.getText();
            System.out.println(interessesText.getText());
        } else if (jCheckBoxPassword.isSelected()) {
            if (passwordText.getText().equals(repeatPassword.getText())) {

                password = passwordText.getText();
            } else {
                return;
            }
        }
        if (jCheckBoxTipoPerfil.isSelected()) {
            if (perfilPublico.isSelected()) {
                publico = 1;
            } else if (perfilPrivado.isSelected()) {
                publico = 0;
            } else {
                JOptionPane.showMessageDialog(this, "Nenhum tipo de perfil selecionado. Por favor escolha um.", "Erro", JOptionPane.ERROR_MESSAGE);
            }
        }
        BufferedImage img = null;
        if (checkAlterarFoto.isSelected()) {

            //generate timestamp string
            newfilename = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date());
            //generate control number (security reasons)
            Random r = new Random();
            int R = r.nextInt(99999 - 10000) + 10000;

            newfilename += Integer.toString(R);

            String userPC = System.getProperty("user.name");

            String url = "C:/Users/" + userPC + "/Documents/NetBeansProjects/BD2012/images/" + newfilename + ".jpg";
            try {
                img = ImageIO.read(this.file);
                File outputfile = new File(url);
                ImageIO.write(img, "jpg", outputfile);
            } catch (IOException ex) {
                Logger.getLogger(MenuRegisto.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        if (newfilename.equals("")) {
            if (connect.updateUser(idR, nome, utilizador, password, datanascimento, sexo, email, pais, cidade, interesses, null, boolPublico, boolAdministrador)) {
                JOptionPane.showMessageDialog(this, "Atualização foi efetuada.", "Sucesso", JOptionPane.INFORMATION_MESSAGE);
            } else {
                JOptionPane.showMessageDialog(this, "Atualização não foi efetuada.", "Erro", JOptionPane.ERROR);
            }
        } else {
            if (connect.updateUser(idR, nome, utilizador, password, datanascimento, sexo, email, pais, cidade, interesses, newfilename, boolPublico, boolAdministrador)) {
                this.sucesso.setVisible(true);
            } else {
                JOptionPane.showMessageDialog(this, "Atualização não foi efetuada.", "Erro", JOptionPane.ERROR_MESSAGE);
            }
        }




        return;
    }//GEN-LAST:event_actualizarActionPerformed

    private void buttonVoltarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonVoltarActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        UtilizadorMenuPrincipal menu = new UtilizadorMenuPrincipal(connect, username, id);
        menu.setVisible(true);
    }//GEN-LAST:event_buttonVoltarActionPerformed

    private void passwordTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_passwordTextActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_passwordTextActionPerformed

    private void jCheckBoxPasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxPasswordActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jCheckBoxPasswordActionPerformed

    private void buttonAnexarFotoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAnexarFotoActionPerformed
        // TODO add your handling code here:
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        int retval = fileChooser.showDialog(this, null);
        file = fileChooser.getSelectedFile();
    }//GEN-LAST:event_buttonAnexarFotoActionPerformed

    private void botaoUtilizadorMenuPrincipalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoUtilizadorMenuPrincipalActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        UtilizadorMenuPrincipal menu = new UtilizadorMenuPrincipal(connect, username, id);
        menu.setVisible(true);
    }//GEN-LAST:event_botaoUtilizadorMenuPrincipalActionPerformed

    private void botaoUtilizadorMenuMensagensPrivadasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoUtilizadorMenuMensagensPrivadasActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        UtilizadorMenuMensagensPrivadas menu = new UtilizadorMenuMensagensPrivadas(connect, username, id);
        menu.setVisible(true);
    }//GEN-LAST:event_botaoUtilizadorMenuMensagensPrivadasActionPerformed

    private void botaoUtilizadorMensagensEnviadasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoUtilizadorMensagensEnviadasActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        UtilizadorMensagensEnviadas menu = new UtilizadorMensagensEnviadas(connect, username, id);
        menu.setVisible(true);
    }//GEN-LAST:event_botaoUtilizadorMensagensEnviadasActionPerformed

    private void botaoUtilizadorMensagensRecebidasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoUtilizadorMensagensRecebidasActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        UtilizadorMensagensRecebidas menu = new UtilizadorMensagensRecebidas(connect, username, id);
        menu.setVisible(true);
    }//GEN-LAST:event_botaoUtilizadorMensagensRecebidasActionPerformed

    private void botaoMenuMensagensNovasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoMenuMensagensNovasActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        UtilizadorMensagensRecebidasNovas menu = new UtilizadorMensagensRecebidasNovas(connect, username, id);
        menu.setVisible(true);
    }//GEN-LAST:event_botaoMenuMensagensNovasActionPerformed

    private void botaoParaUtilizadorMenuEditarPerfilActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoParaUtilizadorMenuEditarPerfilActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        UtilizadorMenuEditarPerfil menu = new UtilizadorMenuEditarPerfil(connect, username, id);
        menu.setVisible(true);
    }//GEN-LAST:event_botaoParaUtilizadorMenuEditarPerfilActionPerformed

    private void botaoRemoveSaiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoRemoveSaiActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        removerUtilizador menu = new removerUtilizador(connect, username, id);
        menu.setVisible(true);
    }//GEN-LAST:event_botaoRemoveSaiActionPerformed

    private void botaoMenuProcurarUtilizadorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoMenuProcurarUtilizadorActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        procurarUtilizadores menu = new procurarUtilizadores(connect, username, id);
        menu.setVisible(true);
    }//GEN-LAST:event_botaoMenuProcurarUtilizadorActionPerformed

    private void botaoMinhasSalasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoMinhasSalasActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        UtilizadorMenuMinhasSalas menu = new UtilizadorMenuMinhasSalas(connect, username, id);
        menu.setVisible(true);
    }//GEN-LAST:event_botaoMinhasSalasActionPerformed

    private void botaoPesquisarSalasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoPesquisarSalasActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        UtilizadorMenuPesquisarSalas menu = new UtilizadorMenuPesquisarSalas(connect, username, id);
        menu.setVisible(true);
    }//GEN-LAST:event_botaoPesquisarSalasActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton actualizar;
    private javax.swing.JMenuBar barraMenus;
    private javax.swing.JMenuItem botaoMenuMensagensNovas;
    private javax.swing.JMenuItem botaoMenuProcurarUtilizador;
    private javax.swing.JMenuItem botaoMinhasSalas;
    private javax.swing.JMenuItem botaoParaUtilizadorMenuEditarPerfil;
    private javax.swing.JMenuItem botaoPesquisarSalas;
    private javax.swing.JMenuItem botaoRemoveSai;
    private javax.swing.JMenuItem botaoUtilizadorMensagensEnviadas;
    private javax.swing.JMenuItem botaoUtilizadorMensagensRecebidas;
    private javax.swing.JMenuItem botaoUtilizadorMenuMensagensPrivadas;
    private javax.swing.JMenuItem botaoUtilizadorMenuPrincipal;
    private javax.swing.JButton buttonAnexarFoto;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton buttonVoltar;
    private javax.swing.JCheckBox checkAlterarFoto;
    private javax.swing.JTextField emailText;
    private javax.swing.JTextArea interessesText;
    private javax.swing.JCheckBox jCheckBoxEmail;
    private javax.swing.JCheckBox jCheckBoxInteresses;
    private javax.swing.JCheckBox jCheckBoxLocalidade;
    private javax.swing.JCheckBox jCheckBoxPassword;
    private javax.swing.JCheckBox jCheckBoxTipoPerfil;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JEditorPane jEditorPane1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField localidadeText;
    private javax.swing.JMenu menuMensagensPrivadas;
    private javax.swing.JMenu menuPerfil;
    private javax.swing.JMenu menuPrincipal;
    private javax.swing.JMenu menuProcurar;
    private javax.swing.JMenu menuSalas;
    private javax.swing.JPasswordField passwordText;
    private javax.swing.JRadioButton perfilPrivado;
    private javax.swing.JRadioButton perfilPublico;
    private javax.swing.JPasswordField repeatPassword;
    private javax.swing.JLabel sucesso;
    // End of variables declaration//GEN-END:variables
}
